cmake_minimum_required(VERSION 2.8)
project(example_mongodb)

# Check dependency libraries
find_library(PROTOBUF_LIB protobuf)
if(NOT PROTOBUF_LIB)
    message(FATAL_ERROR "protobuf library not found")
endif()

find_library(CO_LIB co)
if(NOT CO_LIB)
    message(FATAL_ERROR "co library not found")
endif()

find_library(CORPC_LIB corpc)
if(NOT CORPC_LIB)
    message(FATAL_ERROR "corpc library not found")
endif()

find_library(CORPC_MONGODB_LIB corpc_mongodb)
if(NOT CORPC_MONGODB_LIB)
    message(FATAL_ERROR "corpc_mongodb library not found")
endif()

find_library(BSON_LIB bson-1.0)
if(NOT BSON_LIB)
    message(FATAL_ERROR "bson-1.0 library not found")
endif()

find_library(MONGOC_LIB mongoc-1.0)
if(NOT MONGOC_LIB)
    message(FATAL_ERROR "mongoc-1.0 library not found")
endif()

if (CMAKE_BUILD_TYPE)
else()
    set(CMAKE_BUILD_TYPE RELEASE)
endif()

message("------------ Options -------------")
message("  CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")

set(SOURCE_FILES
    src/main.cpp)

set(CMAKE_VERBOSE_MAKEFILE ON)

# This for mac osx only
set(CMAKE_MACOSX_RPATH 0)

# Set cflags
set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "-std=gnu++11 -fPIC -Wall -pthread")
set(CMAKE_CXX_FLAGS_DEBUG "-g -pg -O0 -DDEBUG=1 ${CMAKE_CXX_FLAGS}")
set(CMAKE_CXX_FLAGS_RELEASE "-g -O3 ${CMAKE_CXX_FLAGS}")

# Add include directories
include_directories(/usr/local/include)
include_directories(/usr/local/include/co)
include_directories(/usr/local/include/corpc)
include_directories(/usr/local/include/corpc/proto)
include_directories(/usr/local/include/libmongoc-1.0)
include_directories(/usr/local/include/libbson-1.0)

# Add target
add_executable(example_mongodb ${SOURCE_FILES})

set(MY_LINK_LIBRARIES -L/usr/local/lib -lmongoc-1.0 -lbson-1.0 -lprotobuf -lcorpc_mongodb -lcorpc -lco -ldl)
target_link_libraries(example_mongodb ${MY_LINK_LIBRARIES})
